package com.tjtt.gwm.action;

import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.tjtt.common.utils.ExcelExportUtil;
import com.tjtt.gwm.service.JiancerenwuTongjiService;
import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.StringUtil;
import com.tjtt.tdm.form.service.IAutoService;

public class JiancerenwuTongjiAction  extends BaseAction{
	private JiancerenwuTongjiService jiancerenwuTongjiService;
	private IAutoService autoService;
	
	/*
	 * 查询检测任务统计列表
	 * wxj
	 */
	public void queryJiancerenwuTJList(){
		try
		{
			String bumnen = StringUtil.encodingUrl(getRequest().getParameter("bumnen"));
			String addtime1 = StringUtil.encodingUrl(getRequest().getParameter("addtime1"));
			String addtime2 = getRequest().getParameter("addtime2");
			Map<String,String> filterMap=getPagerMap();
			if(null!=bumnen && !"".equals(bumnen)){
				bumnen = StringUtil.encodingUrl(bumnen);
				filterMap.put("bumnen", bumnen);
			}
			if(null!=addtime1 && !"".equals(addtime1)){
				filterMap.put("addtime1", addtime1);
			}
			if(null!=addtime2 && !"".equals(addtime2)){
				addtime2 = StringUtil.encodingUrl(addtime2);
				filterMap.put("addtime2", addtime2);
			}
		
			PageResult result= jiancerenwuTongjiService.queryJiancerenwuTJList(filterMap);
			String[] viewArray={"id","t_deptname","renwuzongshu","yiwanchengshu","weiwanchengshu","quxiaorenwushu"};
			String str=getColumnJson(result,viewArray);
			this.setContentType();
			PrintWriter out = getResponse().getWriter();
			out.print(str);
			
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	/*
	 * 导出excel
	 * wxj
	 */
	public void exportExcel(){
//		try {
//			List<String> list = new ArrayList<String>();
//			List<String> facefieldlist = new ArrayList<String>();
//			List<String> fieldlist = new ArrayList<String>();
//			List<String> fieldlist1 =new ArrayList<String>();
//			String extitleName="";
//			String titleNames= StringUtil.encodingUrl(getRequest().getParameter("titleNames"));
//			titleNames = StringUtil.encodingUrl(titleNames);
//			String facefieldsNames= StringUtil.encodingUrl(getRequest().getParameter("fieldsNames"));
//			facefieldsNames = StringUtil.encodingUrl(facefieldsNames);
//			String bumnen = StringUtil.encodingUrl(getRequest().getParameter("bumnen"));
//			String addtime1 = StringUtil.encodingUrl(getRequest().getParameter("addtime1"));
//			String addtime2 = getRequest().getParameter("addtime2");
//			Map<String,Object> filterMap=getPagerMap();
//			if(null!=bumnen && !"".equals(bumnen)){
//				bumnen = StringUtil.encodingUrl(bumnen);
//				filterMap.put("bumnen", bumnen);
//			}
//			if(null!=addtime1 && !"".equals(addtime1)){
//				filterMap.put("addtime1", addtime1);
//			}
//			if(null!=addtime2 && !"".equals(addtime2)){
//				addtime2 = StringUtil.encodingUrl(addtime2);
//				filterMap.put("addtime2", addtime2);
//			}
//			List<Object[]> tongjiList = jiancerenwuTongjiService.queryJiancerenwuTJList2(filterMap);
//			// 第一步，创建一个webbook，对应一个Excel文件  
//	        HSSFWorkbook wb = new HSSFWorkbook();  
//	        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet  
//	        HSSFSheet sheet = wb.createSheet("检测项目统计报表");  
//	        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short  
//	        HSSFRow row = sheet.createRow((int) 0);  
//	        // 第四步，创建单元格，并设置值表头 设置表头居中  
//	        HSSFCellStyle style = wb.createCellStyle();  
//	        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式  
//	  
//	        HSSFCell cell = row.createCell((short) 0);  
//	        cell.setCellValue("序号");  
//	        cell.setCellStyle(style);  
//	        cell = row.createCell((short) 1);  
//	        cell.setCellValue("部门");  
//	        cell.setCellStyle(style);  
//	        cell = row.createCell((short) 2);  
//	        cell.setCellValue("接收任务");  
//	        cell.setCellStyle(style);  
//	        cell = row.createCell((short) 3);  
//	        cell.setCellValue("完成任务");  
//	        cell = row.createCell((short) 4);  
//	        cell.setCellValue("进行中任务");  
//	        cell = row.createCell((short) 5);  
//	        cell.setCellValue("取消的任务");  
//	        cell.setCellStyle(style);  
//			if(null!=tongjiList && tongjiList.size()>0){
//				int i=3;//从第4行开始插入数据
//				for(Object[] objs : tongjiList ){
//						for(int j=0;j<objs.length;j++){
//							et.SetCells(2, i, (j+1), objs[j].toString());
//						}
//						i++;		    
//				}
//			}
	}

	public IAutoService getAutoService() {
		return autoService;
	}

	public void setAutoService(IAutoService autoService) {
		this.autoService = autoService;
	}

	public JiancerenwuTongjiService getJiancerenwuTongjiService() {
		return jiancerenwuTongjiService;
	}

	public void setJiancerenwuTongjiService(
			JiancerenwuTongjiService jiancerenwuTongjiService) {
		this.jiancerenwuTongjiService = jiancerenwuTongjiService;
	}
	
}
